package com.campus.shop.controller.web;


import com.campus.shop.common.Result;
import com.campus.shop.controller.web.vo.OrderFormVo;
import com.campus.shop.controller.web.vo.OrderInfoVo;
import com.campus.shop.controller.web.vo.OrderStatusVo;
import com.campus.shop.service.OrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 统一订单（支付服务）控制器
 *
 * @author xr
 * @since 2024-01-24 10:23:52
 */
@RestController
@RequestMapping("/web/order/")
public class OrderController extends BaseWebController{
    @Resource
    private OrderService orderService;

    /**
     * 创建订单
     * @return
     */
    @PostMapping("/create-order")
    public Result create(@RequestBody OrderFormVo orderFormVo){
        HashMap<String, Object> data = orderService.createOrder(orderFormVo, Integer.valueOf(getUserId()));
        return Result.success(data);
    }

    /**
     * 预支付
     */
    @PostMapping("/pre-pay")
    public Result prePay(@RequestParam("way") Integer way, @RequestParam("orderNo") String orderNo){
        orderService.prePay(way, orderNo, Integer.valueOf(getUserId()));
        return Result.success();
    }

    /**
     * 获取订单详情
     */
    @PostMapping("/get-order-info")
    public Result getOrderInfo(@RequestParam("orderNo") String orderNo){
        OrderInfoVo orderInfo = orderService.getOrderInfo(orderNo, Integer.valueOf(getUserId()));
        return Result.success(orderInfo);
    }

    @PostMapping("/get-order-list")
    public Result getOrderList(){
        List<OrderStatusVo> orderStatusCount =  orderService.getOrderList(Integer.valueOf(getUserId()));
        return Result.success(orderStatusCount);
    }




}


